package com.lujianfei.powerinput.ui.template;

import androidx.appcompat.app.AppCompatActivity;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.lujianfei.powerinput.R;
import com.lujianfei.powerinput.base.BaseActivity;
import com.lujianfei.powerinput.ui.template.base.TemplateAddTypeContract;
import com.lujianfei.powerinput.ui.template.presenter.TemplateAddTypePresenter;
import com.lujianfei.powerinput.utils.ConfigUtils;

import java.util.ArrayList;
import java.util.List;

public class TemplateAddTypeActivity extends BaseActivity implements TemplateAddTypeContract.View {

    private ListView listview;
    private ArrayAdapter adapter;
    private TemplateAddTypeContract.Presenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_template_add_type);
        setTitleMiddleText("添加类型选择");
        listview = findViewById(R.id.listview);
        presenter = new TemplateAddTypePresenter(this);
        initData();
        initEvent();
    }

    private void initEvent() {
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    presenter.onItemClick(adapterView,view,i,l);
            }
        });
    }

    private void initData() {
        presenter.init();
    }

    @Override
    protected int getTitleBarResId() {
        return R.id.custom_titlebar;
    }

    @Override
    public void updateList(List<String> strings) {
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strings);
        listview.setAdapter(adapter);
        if (strings.size() == 1) {
            presenter.onItemClick(null,null,0,0);
        }
    }

    @Override
    public Activity currentActivity() {
        return this;
    }
}
